/*
 * Copyright 2006 Berry Crawford
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.judo.utility.scripts;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.judo.generate.mvc.MVCGenerator;
import org.judo.utility.FileDataReader;
import org.judo.utility.SystemInReader;

public class MVCScript
{
	public static void execute()
	{
		try
		{
			System.out.print("What is the name of the gen-script you would like to run?:");
			String name = SystemInReader.getUserInput();			
			
			File scriptFile = new File("./script/mvc_scripts/"+name+".mvc");
			
			if (scriptFile.exists())
			{			
				MVCGenerator parser = new MVCGenerator(name);
				if (parser.parseScript())
					System.out.print("MVC Code Generated.  Press Enter");
				else
					System.out.print("MVC Code Not Generated.  Press Enter");
				
				SystemInReader.getUserInput();
			}
			else
			{
				System.out.println("Could not find script file: script/mvc_scripts/"+name);
				System.out.print("Press Enter");
				SystemInReader.getUserInput();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.out.println("Could not execute script: "+e);
			System.out.print("Press Enter");
			SystemInReader.getUserInput();
		}
	}
}
